package com.yyc.system.controller;
import com.yyc.core.Result;
import com.yyc.core.ResultGenerator;
import com.yyc.system.model.TUser;
import com.yyc.system.service.ITUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* Created by yyc on 2018/12/26.
*/
@RestController
@RequestMapping("/t/user")
public class TUserController {
    @Autowired
    private ITUserService tUserService;

    @RequestMapping("/add")
    public Result add(@RequestBody TUser tUser) {
        tUserService.save(tUser);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestParam String ids) {
        tUserService.deleteByIds(ids);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody TUser tUser) {
        tUserService.update(tUser);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        TUser tUser = tUserService.findById(id);
        return ResultGenerator.genSuccessResult(tUser);
    }

    @RequestMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<TUser> list = tUserService.findAll();
        PageInfo<TUser> pageInfo = new PageInfo<TUser>(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
    
    //*************************************************************************************
    //批量导入用户数据
    @RequestMapping("/addList")
    public Result addList(@RequestBody List<TUser> userList) {
    	tUserService.saveList(userList);
		return ResultGenerator.genSuccessResult();
    }
}
